﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CarritoCore.Exceptions;

public partial class Login : System.Web.UI.Page
{
    private static CarritoCore.CuentasUsuarios cuentasUsuarios;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (cuentasUsuarios == null)
            {
                lgControl.UserNameRequiredErrorMessage = "Nombre de usuario invalido";
                lgControl.PasswordRequiredErrorMessage = "Contraseña invalida";
                cuentasUsuarios = new CarritoCore.CuentasUsuarios();
            }
        }
    }

    protected void Authenticate_Login(object obj, AuthenticateEventArgs e)
    {
        try
        {
            e.Authenticated = cuentasUsuarios.Authenticar(this.lgControl.UserName, this.lgControl.Password);
        }
        catch (LoginException ex)
        {
            e.Authenticated = false;
            this.lgControl.FailureText = ex.Message;
        }
    }
}